package com.situ.b2c.catalog.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoader;

import com.situ.b2c.catalog.service.CatalogService;
import com.situ.b2c.pojo.Catalog;


@WebServlet("/CatalogDoUpdateServlet")
public class CatalogDoUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
     private CatalogService catalogService;
  
    public CatalogDoUpdateServlet() {
        ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
        catalogService = context.getBean(CatalogService.class);
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Long rowId = Long.parseLong(request.getParameter("rowId"));
		Long parentId=Long.parseLong(request.getParameter("parentId"));
		String cataName = request.getParameter("cataName");
		System.out.println("目录名称" + cataName);
		Integer rankCount = Integer.parseInt(request.getParameter("rankCount"));
		Integer activeFlag = Integer.parseInt(request.getParameter("activeFlag"));
		String updateBy = request.getParameter("updateBy");
		Date updateDate = null;
		try {
			 updateDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("updateDate"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		Catalog catalog = new Catalog();
		catalog.setRowId(rowId);
		catalog.setParentId(parentId);
		catalog.setCataName(cataName);
		catalog.setRankCount(rankCount);
		catalog.setActiveFlag(activeFlag);
		catalog.setUpdateBy(updateBy);
		catalog.setUpdateDate(updateDate);
		
		catalogService.update(catalog);
		
		System.out.println(catalog);
		
		response.sendRedirect("CatalogSelectServlet");
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
